package mylogger

import (
	"fmt"
	"time"
)

// ConsoleLogger 终端答应日志结构体
type ConsoleLogger struct {
	Level LogLevel
}

// NowConsoleLogger 终端打印日志构造函数
func NowConsoleLogger (levelStr string) *ConsoleLogger{

	level,err := parseLogLevel(levelStr)

	if err != nil{
		panic(err)
	}
	return &ConsoleLogger{Level:level}
}


// ConsoleLogger 终端打日志
func (c *ConsoleLogger) log(lv LogLevel, format string,skip int,a ...interface{}) {
	if lv >= c.Level{
		funcName, fileName, lineNo := getInfo(skip)
		msg := fmt.Sprintf(format,a...)
		fmt.Printf("[%s] [%s]\t%s:%s:%d\t%s \n",
			time.Now().Format("2006-01-02 15:04:05.000"),
			getLogLevelstr(lv),
			funcName,
			fileName,
			lineNo,
			msg)
	}


}

// Debug 日志
func (c *ConsoleLogger)  Debug(format string,skip int,a ...interface{}) {
	c.log(DEBUG,format,skip,a...)
}

func (c *ConsoleLogger)  Info(format string,skip int,a ...interface{}) {
	c.log(INFO,format,skip,a...)
}

func (c *ConsoleLogger)  Warning(format string,skip int,a ...interface{}) {
	c.log(WARNING,format,skip,a...)
}
func (c *ConsoleLogger)  Error(format string,skip int,a ...interface{}) {
	c.log(ERROR,format,skip,a...)
}

func (c *ConsoleLogger)  Fatal(format string,skip int,a ...interface{}) {
	c.log(FATAL,format,skip,a...)
}
func(c *ConsoleLogger) Close(){
}